<?php
namespace Home\Controller;
use Common\Controller\CommonController;

/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class HomeController extends CommonController {
 
    /* 
     * 导航栏内容 
     */
    public  function header(){
      $category = D('Common/category')->getSiteCategory();
      $categoryAll = D('Common/category')->getSiteCategory(8);//获取分类
     
      //对seo优化
      $site=C('SITE');
      $logoUrl=M('SiteConfig')->where(array('site_id'=>$site,'title'=>'logo'))->getField('value');//获取到站点的
      //首页
      C('WEB_SITE_TITLE','专业服装搭配_穿衣打扮技巧_服装服饰新闻资讯_全球时尚潮流趋势_衣商网');
      C('WEB_SITE_KEYWORD','服装搭配,穿衣技巧,时尚资讯,穿搭指南');
      C('WEB_SITE_DESCRIPTION','服装搭配,穿衣技巧,时尚资讯,穿搭指南');
      $recordNumber=M('SiteConfig')->where(array('site_id'=>$site,'title'=>'备案号'))->getField('value');//获取到站点的
      $this->assign('recordNumber',$recordNumber);
      $this->assign('logoUrl',$logoUrl);
      $this->assign('categoryAll',$categoryAll);
    }
    
    /*
     *推荐店铺
     */
    public function  recommendShop(){
        //get传送数据，class=2是店铺
       $url=C('MALL_DOMAIN')."/api/index.php?c=goods&a=list4m&brandmost=1&class=1";
       $shopInfo=getApiDataByUrl($url,$data);
       if(S('storeData')){
           $storeData=S('storeData');
       }else{
           foreach ($shopInfo['datas'] as $k=>$v){
               $storeData[$k]['store_name']=$v['store_name'];
               $storeData[$k]['shop_logo']=$v['store_logo'];
               $storeData[$k]['store_introduction']=$v['store_introduction'];
               $storeData[$k]['store_url']=C('MALL_DOMAIN').'/'.$v['store_url'];
           }
           S('storeData',$storeData,604800);
       }    
        if($shopInfo['code']==200){
            $this->assign('shopInfo',$storeData);
        }else{
            return array();
        }
        
        
    }
    
    /* 
    * 列表页左侧的标签内容，分页内容
    * 列表页的文章id集合
    */
    protected  function _listLeftInfo($articleIds=""){
       if($articleIds){
           //文章id找到相关标签
           $articleTags=D('Common/Tags')->getTags($articleIds);
           //对标签的name属性进行统计
           $articleTags=getNameCount($articleTags,'Tags','name');
           $header_tag=array_column($articleTags, "tag_name");
           $header_tag=implode($header_tag, ',');
           C('WEB_SITE_KEYWORD', $header_tag);
           $this->assign('tags',$articleTags);
       }
    } 
    /* 合作伙伴 --友情链接*/
    public  function getCooperateFriend(){
       $where['type']=2;//合作伙伴
       $where['is_valid']=1;//有效
       $where['front_display']=1;//在首页显示
       $where['belong_client']=1;//在pc端显示
       //获取到合作伙伴的信息
       $cooperate=M('FriendLink')->field('name,img,link')->order('sort desc ')->where($where)->select();
       //获取到友情链接
       $where['type']=1;//友情链接
       $friendLink=M('FriendLink')->field('name,img,link')->order('sort desc')->where($where)->select();
       //dump(M('FriendLink')->getLastSql());exit;
       $this->assign('cooperate',$cooperate);
       $this->assign('friendLink',$friendLink);
    }
    
    /*获取到首页的广告  */
    protected function getHomeAd(){
        $ad=M('AdvertiseContent');
        $where['effect']=1;
        //获取广告内容1:Slide幻灯片2:Home_left首页左13:Home_right首页右4:Home_bottom首页中间5:Home_bottom首页底部6:Details_top详情顶部7:Home_left首页左2 8:Home_left首页左3
        $topAd=$ad->where('category_id=1')->order('sort')->where($where)->limit(3)->select();
        $footerAd=$ad->where('category_id=5')->order('sort')->where($where)->find();
       // $rightAd=$ad->where('category_id=5')->order('sort')->find();
        //右侧广告
        $rightAd=$ad->where('category_id=3')->order('sort')->where($where)->find();
        $righttwoAd=$ad->where('category_id=7')->order('sort')->where($where)->find();
        $rightthreeAd=$ad->where('category_id=8')->order('sort')->where($where)->find();
        $rightfourAd=$ad->where('category_id=9')->order('sort')->where($where)->find();
        $rightfiveAd=$ad->where('category_id=10')->order('sort')->where($where)->find();
      
        //$centerAd=$ad->where('category_id=4')->page($p,6)->order('sort')->where($where)->select();
        /* $ad=D('Common/AdvertiseContent');
         $topAd=$ad->get_position_ad(1);
         $rightAd=$ad->get_position_ad(3);
         $footerAd=$ad->get_position_ad(5);
         $centerAd=$ad->get_position_ad(4); */
       
        $centerAdAll=$ad->where('category_id=4')->limit(6)->order('sort')->select();
        if($p>1){
            $len=sizeof($centerAd);
            for($i=1;$i+$len<=6;$i++){
                $centerAd[$len+$i-1]=$centerAdAll[$i+$len-1];
            }
        }
        $this->assign('topAd',$topAd);
        $this->assign('footerAd',$footerAd);
        $this->assign('centerAd',$centerAd);
        $this->assign('rightAd',$rightAd);
        $this->assign('righttwoAd',$righttwoAd);
        $this->assign('rightthreeAd',$rightthreeAd);
        $this->assign('rightfourAd',$rightfourAd);
        $this->assign('rightfiveAd',$rightfiveAd);
    }
}
